package com.emily.login.controller;


import com.emily.log.api.LogApi;
import com.emily.login.dao.entity.SysUser;
import com.emily.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private  RestTemplate template;
    @Autowired
    private LogApi logApi;
    @Autowired
    private LoginService loginService;
    @PostMapping
    public String login(String username, String password) {

      //  String status = template.getForObject("http://SPC-SERVICE-LOG/log/printLog?info=" +password, String.class);
        String status = logApi.printLog(username + "," + password);
        SysUser sysUser = loginService.login(username, password);
        if(sysUser == null){
            return "登录失败，用户名不存在";
        }else {
            return  "登录" + status + ",欢迎：" + sysUser.getTrueName();
        }
    }
}
